import axios from "axios";
import { MessageBox } from 'element-ui';
import  storeApi from "@/utils/storeage.js"
import * as api from "@/api/permission"
//配置axios

let http = axios.create({
    baseURL: "/api",
    timeout: 10000,
    withCredentials: true,//携带本地认证
})

//配置全局请求拦截
//对接口的请求进行统一处理
http.interceptors.request.use((config) => {
    //获取本地token
    let token =  storeApi.get("cgtoken");
    config.headers['authorization'] = token;
    api.getPermissionApi().then(res =>{
        console.log(res);
    })
    return config;//放行
})

//配置全局响应拦拦截
//对结果进行统一的处理
http.interceptors.response.use((config) => {
    let { state,msg } = config.data;
    if (!state) {
        //错误处理一般下在响应拦截器中
        MessageBox({
            message:msg,
            title:"错误提示",
            type:"error"
        })
    }
    return config;
})

export default http;